<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card  style = "color: #3F5EFB">
          <div>住户总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            <span>{{residentNumber}}</span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div style = "color: #3F5EFB">访客数量</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            <span>{{visitorNumber}}</span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div style = "color: #3F5EFB">中高风险地区人数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            <span>{{hightNumber}}</span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div style = "color: #3F5EFB">房屋数量</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            <span>{{addressNumber}}</span>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px; height: 450px"></div>
      </el-col>
      <el-col  :span="12">
        <div id="pie" style="width: 500px; height: 400px"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'


export default {
  name: "Home",
  data() {
    return{
      visitorNumber:"",
      addressNumber:"",
      hightNumber:"",
      residentNumber:"",

    }
  },
  created() {
    this.request.get("/echarts/getFour").then(res => {
      this.residentNumber =res.data[0]
      this.visitorNumber =res.data[1]
      this.hightNumber =res.data[2]
      this.addressNumber =res.data[3]
    })
  },
  mounted() {
    var option;
    var pieOption;


    option = {
      title: {
        text: '统计',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name:"住户增加数量",
          data: [],
          type: 'line'
        },
        {
          name:"住户增加数量",
          data: [],
          type: 'bar'
        },
        {
          name:"访客数量",
          data: [],
          type: 'line'
        },
        {
          name:"访客数量",
          data: [],
          type: 'bar'
        }
      ]
    };
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);

    this.request.get("/echarts/members").then(res => {
      // 填空
      option.series[0].data = res.data
      option.series[1].data = res.data
      // 数据准备完毕之后再set
      myChart.setOption(option);

    })
    this.request.get("/echarts/vis").then(res => {
      // 填空
      option.series[2].data = res.data
      option.series[3].data = res.data
      // 数据准备完毕之后再set
      myChart.setOption(option);

    })

    //饼图
    pieOption = {
      title: {
        text: '风险统计',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: '60%',
          label:{            //饼图图形上的文本标签
            normal:{
              show:true,
              position:'inner', //标签的位置
              textStyle : {
                fontWeight : 300 ,
                fontSize : 14,    //文字的字体大小
                color: "#fff"
              },
              formatter:'{d}%'
            }
          },
          data: [],  // 填空
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    var PieDom = document.getElementById('pie');
    var PieChart = echarts.init(PieDom);
    this.request.get("/echarts/members").then(res => {
      pieOption.series[0].data = [
        {name: "低风险险", value: res.data[0]},
        {name: "中高风险", value: res.data[1]},
      ]
      PieChart.setOption(pieOption)
    })

  }
}
</script>

<style scoped>

</style>